from Crypto.Random import random
from Crypto.PublicKey import RSA
from Crypto.Hash import SHA
def dsa(filepath):
    file = open(filepath,'r+',encoding = 'utf-8')
    message = file.read()
    file.close()
    key = RSA.generate(1024)
    h = SHA.new(message.encode("utf8")).digest()
    k = random.StrongRandom().randint(1,key.q-1)
    sig = key.sign(h,k)
    file = open(filepath,'a+',encoding = 'utf-8')
    file.write(str(sig))
    file.close()

if __name__ == '__main__':
    filepath = "input.txt"
    dsa(filepath)